__author__ = 'guo'

from extends.BaseHandle import BaseHandle



class Admin(BaseHandle):
    def get(self, *args, **kwargs):
        return self.render("admin/index.html")

    def post(self, *args, **kwargs):
        test = '<img width="200" height="460" src="/static/img/meinv.jpg" class="attachment-medium" alt="100" />'
        self.write(test)





class Catelog(BaseHandle):
    def get(self, *args, **kwargs):
        cateloglist = self.db.catelog.find()
        return self.render("admin/catelog.html", cateloglist=cateloglist)


    def post(self, *args, **kwargs):
        import time
        name = self.get_argument("catelog", '')
        self.db.catelog.find({})
        catelogRows = self.db.catelog.find({"name": name}).count()
        data = {}
        if catelogRows > 0:
            data['code'] = 201
            data['message'] = "已经有此类目"
            return self.api_response(data)
        self.db.catelog.insert(
            {
                "name": name,
                "create": time.time(),
                "parent": ''
            },
        )

        data['code'] = 200
        data['message'] = "成功"
        return self.api_response(data)





class User(BaseHandle):
    def get(self, *args, **kwargs):
        userlist = self.db.user.find()
        return self.render("admin/user.html", userlist=userlist)

    #
    # def post(self, *args, **kwargs):
    #     import time
    #     name = self.get_argument("catelog", '')
    #     self.db.catelog.find({})
    #     catelogRows = self.db.catelog.find({"name": name}).count()
    #     data = {}
    #     if catelogRows > 0:
    #         data['code'] = 201
    #         data['message'] = "已经有此类目"
    #         return self.api_response(data)
    #     self.db.catelog.insert(
    #         {
    #             "name": name,
    #             "create": time.time(),
    #             "parent": ''
    #         },
    #     )
    #
    #     data['code'] = 200
    #     data['message'] = "成功"
    #     return self.api_response(data)
